//
//  UIBarButtonItem+extension.swift
//  微博
//
//  Created by YJW on 16/8/6.
//  Copyright © 2016年 yijiang. All rights reserved.
//

//import Foundation

import UIKit

extension UIBarButtonItem{
    
//    let btn = UIButton()
//    btn.setTitle("添加还有", for: .normal)
//    btn.setTitleColor(UIColor.orange(), for: .highlighted)
//    btn.sizeToFit()
//    btn.addTarget(self, action: #selector(setDemo), for: .touchUpInside)
//    
//    navigationItem.rightBarButtonItem = UIBarButtonItem(customView: btn)
    ///自定义 UIBarButtonItem
    convenience init(name:String, size:CGFloat = 16,target: AnyObject?, action: Selector,isBack:Bool = false) {
        
        let btn = UIButton()
        btn.setTitle(name, for: UIControlState(rawValue: 0))
        btn.setTitleColor(UIColor.gray(), for: UIControlState(rawValue: 0))
        btn.setTitleColor(UIColor.orange(), for: .highlighted)
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: size)
        
        if isBack {
            let imgName = "navigationbar_back"
            
            btn.setImage(UIImage(named:imgName), for: UIControlState(rawValue: 0))
            btn.setImage(UIImage(named:imgName + "_highlighted"), for: .highlighted)
        }
        
        btn.sizeToFit()
        self.init(customView:btn)
    }
}


